package com.practice.page.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.practice.page.PageDto;
import com.practice.page.PageResult;
import com.practice.page.PageService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分页查询
 *
 * @author Masiyu
 * @date 2024/3/8 9:47
 */
@Service
public class PageServiceImpl implements PageService {
    @Override
    public PageResult page(PageDto req, List content) {
        PageHelper.startPage(req.getParam().getPageNum(),
                             req.getParam().getPageSize(),
                             req.getParam().getOrderBy());
        PageInfo pageInfo = new PageInfo<>(content);
        PageResult result = new PageResult<>();
        BeanUtils.copyProperties(pageInfo,result);
        return result;
    }
    
}
